//
//  SecondViewController.m
//  UI豆瓣2015到2016跨年作业
//
//  Created by LHY on 15/12/31.
//  Copyright © 2015年 Lanou 32 李昊宇. All rights reserved.
//

#import "SecondViewController.h"
#import "UIImageView+WebCache.h"
#import "TypeMovieViewController.h"
#import "MovieDetailsViewController.h"
@interface SecondViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (nonatomic , retain) UITableView *tableView;
@property (nonatomic , retain) NSMutableArray *arrModel;


@end

@implementation SecondViewController

- (void)dealloc
{
    [_arrModel release];
    [_tableView release];
    [super dealloc];
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationController.navigationBar.translucent = NO;
    UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"/Users/dllo/Desktop/豆瓣所有/UI豆瓣2015到2016跨年作业/UI豆瓣2015到2016跨年作业/btn_nav_list@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal/**保证图片不被渲染 */] style:UIBarButtonItemStylePlain target:self action:@selector(action1:)];
    self.navigationItem.rightBarButtonItem = item3;
    self.navigationItem.title = @"电影";
   self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.5 alpha:1];
    self.navigationController.navigationBar.backgroundColor = [UIColor cyanColor];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    [_tableView release];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self DataMovie];
    
    [_tableView registerClass:[OTableViewCell class] forCellReuseIdentifier:@"cell"];
    
//    self.navigationItem.leftBarButtonItem = self.editButtonItem;


}

- (void)action1:(UIBarButtonItem *)action {

    TypeMovieViewController *type = [[TypeMovieViewController alloc] init];
   
    
    [self.navigationController pushViewController:type animated:YES];
    
    [type release];
    




}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 160;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _arrModel.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    ModelMovie *mom = _arrModel[indexPath.row];
    cell.label.text = mom.title;
    [cell.image sd_setImageWithURL:[NSURL URLWithString:mom.image]];
    //    cell.backgroundColor = [UIColor cyanColor];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MovieDetailsViewController *mov = [[MovieDetailsViewController alloc] init];
    mov.index = indexPath;
    
    [self.navigationController pushViewController:mov animated:YES];
    [mov release];
    
   


}



- (void)DataMovie {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"plist"];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    self.arrModel = [NSMutableArray array];
    for (NSDictionary *dic in arr) {
        ModelMovie *mod = [ModelMovie modelMovie];
        [mod setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:mod];
        
    }
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
